<template>
  <div class="comment">
    <!-- 按钮 -->
    <div class="btns">
      <el-button size="small" type="primary" @click="toAdd">添加</el-button>
    </div>
    <!-- 表格 -->
    <el-table :data="list" style="width: 100%" size="small">
      <el-table-column type="index" label="序号"> </el-table-column>
      <el-table-column prop="content" label="阅读心得" width="180"> </el-table-column>
      <el-table-column prop="commentDate" label="评论日期"> </el-table-column>
      <el-table-column prop="status" label="评价分数"> </el-table-column>
<el-table-column prop="articleId" label="文章署名"> </el-table-column>
<el-table-column prop="userId" label="用户"> </el-table-column>
<el-table-column prop="parent" label="作者"> </el-table-column>
      <el-table-column label="操作" width="150" align="center"> 
        <template v-slot="scope">
          <el-button size="small" type="danger" @click="del(scope.row)">删除</el-button>
          <el-button size="small" type="primary" @click="edit(scope.row)">修改</el-button>
        </template>
      </el-table-column>
    </el-table>

     <!-- 带图 -->
     <el-row>
  <el-col :span="50" v-for="(o, index) in 1" :key="o" :offset="index > 0 ? 3: 0">
    <el-card :body-style="{ padding: '0px' }">
 
       <img src="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1593893604007&di=7d114efc2066c2b3bde66b9385a725ae&imgtype=0&src=http%3A%2F%2Fimg.mp.itc.cn%2Fupload%2F20160816%2F41059926cbd04113a8f0a7458a17ba8a_th.gif" class="image">
      <div style="padding: 14px;">
        <span>感谢评论</span>
        <div class="bottom clearfix">
          <time class="time">{{ currentDate }}</time>
       
        </div>
      </div>
    </el-card>
  </el-col>
</el-row>

  


    <!-- 模态框 -->
    <el-dialog
      class="customer_modal"
      title="添加Test"
      :visible.sync="dialogVisible"
      width="60%">
      {{form}}
      <el-form :model="form" label-width="100px">
        <el-form-item label="阅读心得" >
          <el-input v-model="form.content"></el-input>
        </el-form-item>
        <el-form-item label="评论日期" >
          <el-input v-model="form.commentDate"></el-input>
        </el-form-item>
        <el-form-item label="评价分数" >
          <el-input v-model="form.status"></el-input>
        </el-form-item>
 <el-form-item label="文章署名" >
          <el-input v-model="form.articleId"></el-input>
        </el-form-item>
 <el-form-item label="用户" >
          <el-input v-model="form.userId"></el-input>
        </el-form-item>
         <el-form-item label="作者" >
          <el-input v-model="form.parent"></el-input>
        </el-form-item>
      </el-form>
      
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" size="small">取 消</el-button>
        <el-button type="primary" @click="save" size="small">确 定</el-button>
      </span>
    </el-dialog>

  </div>
</template>




<script>
// 导入request , 浏览器提供给我们的用于与后台进行交互的工具 api
import {get,post} from '@/utils/request'
export default {
  data (){
    return {
      form:{},
      list:[],
      dialogVisible:false
    }
  },
  created(){
    this.loadData();
  },
  methods:{
    // 保存
    save(){
      let url = "/comment/saveOrUpdate"
      post(url,this.form).then( (response)=>{
        // 1. 模态框关闭
        this.dialogVisible = false;
        // 2. 提示
        this.$message({type:"success",message:response.message})
        // 3. 刷新
        this.loadData();
      } )
    },
    // 删除
 del(row){
      this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          let url = "/comment/deleteById"
          get(url,{id:row.id}).then( (response)=>{
            // 1. 提示
            this.$message({type:"success",message:response.message})
            // 2. 刷新 
            this.loadData();
          } )
        })
    },
    // 编辑
    edit(row){
      this.form = row;
      this.dialogVisible = true;
    },
    // 加载数据
    loadData(){
      let url = "/comment/findAll";
      get(url).then( (response)=>{
        // response就是后端返回给我们的Message{status,message,data,timestamp}
        this.list = response.data;
      } );
    },
    toAdd(){
      this.dialogVisible = true;
    }
  }


}
</script>
